import { getUmsToken } from '@/utils/cookies'

// 封装路由跳转函数
const routeInterceptor = {
  invoke(args) {
    const { setLogOut } = useUserStore()
    if (!getUmsToken() && !args.url.includes('/pages/login/index')) {
      uni.showToast({
        title: '请先登录',
        icon: 'none'
      })
      setLogOut()
      return false
    }
    return true
  },
  success(args) {
    // console.log('routeInterceptor-success', args)
  },
  fail(err) {
    // console.log('routeInterceptor-fail', err)
  },
  complete(res) {
    // console.log('routeInterceptor-complete', res)
  }
}

uni.addInterceptor('navigateTo', routeInterceptor)
uni.addInterceptor('redirectTo', routeInterceptor)
uni.addInterceptor('reLaunch', routeInterceptor)
uni.addInterceptor('switchTab', routeInterceptor)
